home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Pen to Draw Lines and Shapes / Drawing a Line Filled with a Texture / GDITEST25.dpr
Encoding:
Text File  |  2003-10-15  |  2.4 KB  |  96 lines

  1. program GDITEST25;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   pen: TGPPen;
  15.   image: TGPImage;
  16.   Brush: TGPTextureBrush;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   image := TGPImage.Create('..\..\Media\Texture1.jpg');
  20.   Brush := TGPTextureBrush.Create(image);
  21.   Pen := TGPPen.Create(Brush, 30);
  22.   graphics.DrawImage(image, 0, 0, image.GetWidth, image.GetHeight);
  23.   graphics.DrawEllipse(Pen, 100, 20, 200, 100);
  24.   pen.Free;
  25.   image.Free;
  26.   Brush.Free;
  27.   graphics.Free;
  28. end;
  29.  
  30.  
  31. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  32. var
  33.   Handle: HDC;
  34.   ps: PAINTSTRUCT;
  35. begin
  36.   case message of
  37.     WM_PAINT:
  38.       begin
  39.         Handle := BeginPaint(Wnd, ps);
  40.         OnPaint(Handle);
  41.         EndPaint(Wnd, ps);
  42.         result := 0;
  43.       end;
  44.  
  45.     WM_DESTROY:
  46.       begin
  47.         PostQuitMessage(0);
  48.         result := 0;
  49.       end;
  50.  
  51.    else
  52.       result := DefWindowProc(Wnd, message, wParam, lParam);
  53.    end;
  54. end;
  55.  
  56. var
  57.   hWnd     : THandle;
  58.   Msg      : TMsg;
  59.   wndClass : TWndClass;
  60. begin
  61.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  62.    wndClass.lpfnWndProc    := @WndProc;
  63.    wndClass.cbClsExtra     := 0;
  64.    wndClass.cbWndExtra     := 0;
  65.    wndClass.hInstance      := hInstance;
  66.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  67.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  68.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  69.    wndClass.lpszMenuName   := nil;
  70.    wndClass.lpszClassName  := 'GettingStarted';
  71.  
  72.    RegisterClass(wndClass);
  73.  
  74.    hWnd := CreateWindow(
  75.       'GettingStarted',       // window class name
  76.       'Drawing a Line Filled with a Texture',      // window caption
  77.       WS_OVERLAPPEDWINDOW,    // window style
  78.       Integer(CW_USEDEFAULT), // initial x position
  79.       Integer(CW_USEDEFAULT), // initial y position
  80.       Integer(CW_USEDEFAULT), // initial x size
  81.       Integer(CW_USEDEFAULT), // initial y size
  82.       0,                      // parent window handle
  83.       0,                      // window menu handle
  84.       hInstance,              // program instance handle
  85.       nil);                   // creation parameters
  86.  
  87.    ShowWindow(hWnd, SW_SHOW);
  88.    UpdateWindow(hWnd);
  89.  
  90.    while(GetMessage(msg, 0, 0, 0)) do
  91.    begin
  92.       TranslateMessage(msg);
  93.       DispatchMessage(msg);
  94.    end;
  95. end.
  96.